package com.mantru.iotpot.setting.Adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.mantru.iotpot.R;

import java.util.List;

public class MyWiFiAdapter extends RecyclerView.Adapter<MyWiFiAdapter.ViewHolder>{
    private final List<String> wifiList;

    public MyWiFiAdapter(List<String> wifiList) {
        this.wifiList = wifiList;
    }
    @NonNull
    @Override
    public MyWiFiAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_my_wifi, parent, false);
        return new MyWiFiAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyWiFiAdapter.ViewHolder holder, int position) {
        String wifiInfo = wifiList.get(position);
        Log.d("MyWiFiAdapter","wifiInfo: " + wifiInfo);
        if (wifiInfo.equals("<unknown ssid>")){
            holder.box.setVisibility(View.GONE);
        }else {
            holder.name.setText(wifiInfo);
            holder.situation.setVisibility(View.VISIBLE);
            holder.connecte.setVisibility(View.VISIBLE);
        }

    }

    @Override
    public int getItemCount() {
        return wifiList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{

        private final ImageView situation;
        private final TextView name;
        private final TextView connecte;
        private final RelativeLayout box;

        public ViewHolder(View view){
            super(view);
            situation = view.findViewById(R.id.adapter_my_wifi_connection_situation);
            name = view.findViewById(R.id.adapter_my_wifi_name);
            connecte = view.findViewById(R.id.adapter_my_wifi_connecte);
            box = view.findViewById(R.id.adapter_my_wifi_box);
        }
    }
}
